from file_define import TextFileReader,JsonFileReader,FileReader
from data_define import Record
from pyecharts.charts import Bar
from pyecharts.options import *
from pyecharts.globals import ThemeType

text_file = TextFileReader("D:/date.txt")
json_file = JsonFileReader("D:/date1.txt")

jan_data:list[Record] = text_file.read_data()
feb_data:list[Record] = json_file.read_data()

all_data:list[Record] = jan_data+feb_data

data_dict={}
for record in all_data:
    if record.date in data_dict.keys():
        data_dict[record.date]+=record.money
    else:
        data_dict[record.date]=record.money

#可视化图表
bar = Bar(init_opts=InitOpts(theme=ThemeType.LIGHT))

bar.add_xaxis(list(data_dict.keys()))
bar.add_yaxis("销售额",list(data_dict.values()),label_opts=LabelOpts(is_show=False))
bar.set_global_opts(
    title_opts=TitleOpts(title="每日销售额")
)

bar.render("每日销售额柱状图.html")